package GoodsService

import (
	"context"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/response/GoodsResp"
	"github.com/gogf/gf/frame/g"
	"strings"
)

func GetGoodsOptionsById(ctx context.Context, id int) *GoodsResp.GoodsOption {
	goodsOption := GoodsResp.GoodsOption{}
	err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "goods_option").Where("id",
		id,
	).Order("display_sort DESC").Struct(&goodsOption)
	if err != nil {
		g.Log().Error("GetGoodsOptionsById " + err.Error())
		return nil
	}
	goodsOption.TitleArr = strings.Split(goodsOption.Title, ";")
	goodsOption.Title = strings.ReplaceAll(goodsOption.Title, ";", ",")
	return &goodsOption
}
